# UIFunctions.py 修改后
from PySide6.QtCore import QPoint, QEasingCurve, Qt, QPropertyAnimation
from PySide6.QtGui import QMouseEvent
from PySide6.QtWidgets import QMainWindow, QWidgetItem, QLayoutItem

class UIFunctions:
    def __init__(self, window):
        self.window = window  # 保存主窗口引用
        self.drag_position = QPoint()
        
    def enable_dragging(self):
        """启用窗口拖动功能"""
        self.window.mousePressEvent = self.mouse_press_event
        self.window.mouseMoveEvent = self.mouse_move_event

    def mouse_press_event(self, event: QMouseEvent):
        """鼠标按下事件"""
        if event.button() == Qt.LeftButton:
            self.drag_position = event.globalPosition().toPoint() - self.window.frameGeometry().topLeft()
            event.accept()

    def mouse_move_event(self, event: QMouseEvent):
        """鼠标移动事件"""
        if event.buttons() == Qt.LeftButton:
            self.window.move(event.globalPosition().toPoint() - self.drag_position)
            event.accept()

    # 保持原有toggleMenu方法
    def toggleMenu(self, ui, enable):
        if enable:
            standard = 68
            maxExtend = 180
            width = ui.LeftBar.width()
            widthExtended = maxExtend if width == standard else standard
            
            self.animation = QPropertyAnimation(ui.LeftBar, b"minimumWidth")
            self.animation.setDuration(400)
            self.animation.setStartValue(width)
            self.animation.setEndValue(widthExtended)
            self.animation.setEasingCurve(QEasingCurve.InOutQuint)
            self.animation.start()

   